﻿namespace h3
{
    public class MyMath
    {
        public double Add(double a, double b)
        {
            return a + b;
        }

        public double Subtract(double a, double b)
        {
            return a - b;
        }

        public double Multiply(double a, double b)
        {
            return a * b;
        }

        public double Divide(double a, double b)
        {
            if (b == 0)
            {
                throw new DivideByZeroException("除数不能为0");
            }
            return a / b;
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            MyMath math = new MyMath();

            double sum = math.Add(10, 5);
            Console.WriteLine($"10 + 5 = {sum}");

            double difference = math.Subtract(10, 5);
            Console.WriteLine($"10 - 5 = {difference}");

            double product = math.Multiply(10, 5);
            Console.WriteLine($"10 * 5 = {product}");

            try
            {
                double quotient = math.Divide(10, 5);
                Console.WriteLine($"10 / 5 = {quotient}");
            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine($"除法错误: {ex.Message}");
            }

            try
            {
                double quotient = math.Divide(10, 0);
                Console.WriteLine($"10 / 0 = {quotient}");
            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine($"除法错误: {ex.Message}");
            }

            double decimalSum = math.Add(3.5, 2.5);
            Console.WriteLine($"3.5 + 2.5 = {decimalSum}");

            double decimalProduct = math.Multiply(2.5, 4);
            Console.WriteLine($"2.5 * 4 = {decimalProduct}");
        }
    }

}
